Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 672)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 12.96776 12.96713 12.96650 12.96588 12.96526 12.96464 12.96402 12.96340
## [9] 12.96277 12.96214 12.96149 12.96084 12.96017 12.95948 12.95878 12.95805
## [17] 12.95731 12.95654 12.95574 12.95491 12.95405 12.95316 12.95223 12.95126
## [25] 12.95026 12.94921 12.94812 12.94698 12.94579 12.94456 12.94326 12.94192
## [33] 12.94051 12.93905 12.93753 12.93594 12.93427 12.93250 12.93065 12.92871
## [41] 12.92670 12.92461 12.92247 12.92026 12.91800 12.91570 12.91336 12.91099
## [49] 12.90859 12.90617 12.90373 12.90129 12.89885 12.89641 12.89398 12.89157
## [57] 12.88919 12.88683 12.88451 12.88224 12.88001 12.87783 12.87572 12.87367
## [65] 12.87170 12.86981 12.86800 12.86629 12.86467 12.86316 12.86177 12.86024
## [73] 12.85836 12.85614 12.85362 12.85080 12.84773 12.84441 12.84087 12.83713
## [81] 12.83322 12.82916 12.82497 12.82067 12.81629 12.81185 12.80737 12.80287
## [89] 12.79839 12.79393 12.78952 12.78519 12.78096 12.77685 12.77289 12.76908
## [97] 12.76547 12.76207 12.75890 12.75599 12.75336 12.75104 12.74903 12.74738
## [105] 12.74609 12.74520 12.74432 12.74308 12.74153 12.73971 12.73766 12.73541
## [113] 12.73302 12.73051 12.72793 12.72532 12.72272 12.72017 12.71772 12.71540
## [121] 12.71325 12.71131 12.70963 12.70824 12.70719 12.70651 12.70625 12.70645
## [129] 12.70714 12.70838 12.71019 12.71262 12.71571 12.71950 12.72403 12.73012
## [137] 12.73843 12.74874 12.76083 12.77451 12.78954 12.80573 12.82286 12.84072
## [145] 12.85909 12.87776 12.89652 12.91516 12.93346 12.95122 12.96821 12.98423
## [153] 12.99907 13.01251 13.02434 13.03435 13.04451 13.05676 13.07084 13.08648
## [161] 13.10341 13.12138 13.14010 13.15931 13.17876 13.19816 13.21726 13.23579
## [169] 13.25348 13.27007 13.28528 13.29886 13.31053 13.32003 13.32710 13.33319
## [177] 13.33989 13.34710 13.35474 13.36273 13.37096 13.37937 13.38785 13.39632
## [185] 13.40470 13.41289 13.42081 13.42837 13.43548 13.44205 13.44800 13.45324
## [193] 13.45768 13.46124 13.46382 13.46533 13.46570 13.46483 13.46263 13.45902
## [201] 13.45391 13.44721 13.43883 13.42869 13.41599 13.40028 13.38191 13.36126
## [209] 13.33871 13.31464 13.28940 13.26339 13.23698 13.21053 13.18442 13.15903
## [217] 13.13473 13.11190 13.09091 13.06887 13.04289 13.01339 12.98075 12.94539
## [225] 12.90769 12.86807 12.82691 12.78462 12.74160 12.69825 12.65496 12.61214
## [233] 12.57018 12.52949 12.49047 12.45351 12.41902 12.38739 12.35903 12.33433
## [241] 12.31125 12.28758 12.26346 12.23901 12.21437 12.18968 12.16508 12.14069
## [249] 12.11665 12.09309 12.07016 12.04798 12.02669 12.00643 11.98733 11.96952
## [257] 11.95314 11.93832 11.92520 11.91485 11.90797 11.90411 11.90283 11.90370
## [265] 11.90628 11.91012 11.91479 11.91986 11.92488 11.92941 11.93301 11.93525
## [273] 11.93569 11.93388 11.92940 11.92435 11.92102 11.91919 11.91866 11.91922
## [281] 11.92067 11.92279 11.92539 11.92826 11.93118 11.93396 11.93638 11.93824
## [289] 11.93934 11.93947 11.93841 11.93597 11.93193 11.92610 11.91926 11.91235
## [297] 11.90536 11.89828 11.89109 11.88379 11.87637 11.86881 11.86112 11.85327
## [305] 11.84525 11.83707 11.82870 11.82014 11.81138 11.80240 11.79320 11.78377
## [313] 11.77410 11.76417 11.75399 11.74118 11.72386 11.70269 11.67833 11.65144
## [321] 11.62269 11.59274 11.56225 11.53190 11.50233 11.47422 11.44824 11.42503
## [329] 11.40527 11.38962 11.37875 11.36969 11.35921 11.34757 11.33502 11.32180
## [337] 11.30818 11.29441 11.28074 11.26743 11.25472 11.24287 11.23214 11.22277
## [345] 11.21502 11.20915 11.20540 11.20403 11.20529 11.20943 11.21651 11.22620
## [353] 11.23827 11.25244 11.26847 11.28608 11.30504 11.32507 11.34592 11.36733
## [361] 11.38905 11.41081 11.43236 11.45344 11.47380 11.49317 11.51352 11.53685
## [369] 11.56292 11.59151 11.62238 11.65530 11.69005 11.72638 11.76408 11.80291
## [377] 11.84264 11.88304 11.92388 11.96494 12.00597 12.04675 12.08705 12.12664
## [385] 12.16529 12.20277 12.23884 12.27328 12.30586 12.33635 12.36451 12.39012
## [393] 12.41628 12.44586 12.47831 12.51305 12.54951 12.58714 12.62536 12.66361
## [401] 12.70131 12.73791 12.77284 12.80553 12.83541 12.86192 12.88449 12.90256
## [409] 12.91747 12.93100 12.94322 12.95416 12.96391 12.97251 12.98002 12.98651
## [417] 12.99203 12.99663 13.00039 13.00335 13.00558 13.00714 13.00808 13.00846
## [425] 13.00835 13.00780 13.00686 13.00379 12.99708 12.98719 12.97456 12.95963
## [433] 12.94286 12.92469 12.90557 12.88594 12.86626 12.84696 12.82850 12.81133
## [441] 12.79588 12.78261 12.77197 12.76124 12.74763 12.73143 12.71294 12.69244
## [449] 12.67023 12.64662 12.62189 12.59634 12.57026 12.54395 12.51771 12.49183
## [457] 12.46660 12.44232 12.41929 12.39779 12.37813 12.36060 12.34550 12.33311
## [465] 12.32215 12.31113 12.30012 12.28915 12.27826 12.26752 12.25695 12.24661
## [473] 12.23655 12.22680 12.21742 12.20845 12.19994 12.19193 12.18446 12.17759
## [481] 12.17136 12.16582 12.16101 12.15680 12.15303 12.14971 12.14686 12.14447
## [489] 12.14255 12.14111 12.14016 12.13970 12.13974 12.14029 12.14136 12.14294
## [497] 12.14506 12.14770 12.15090 12.15525 12.16129 12.16886 12.17781 12.18801
## [505] 12.19929 12.21152 12.22454 12.23822 12.25239 12.26691 12.28164 12.29643
## [513] 12.31113 12.32559 12.33967 12.35321 12.36607 12.37811 12.38917 12.39911
## [521] 12.40962 12.42238 12.43716 12.45375 12.47194 12.49152 12.51227 12.53398
## [529] 12.55643 12.57942 12.60272 12.62613 12.64944 12.67242 12.69487 12.71657
## [537] 12.73731 12.75688 12.77507 12.79165 12.80642 12.81916 12.82966 12.83771
## [545] 12.84310 12.84560 12.84652 12.84724 12.84771 12.84790 12.84776 12.84724
## [553] 12.84629 12.84487 12.84293 12.84042 12.83731 12.83353 12.82905 12.82382
## [561] 12.81779 12.81092 12.80315 12.79445 12.78477 12.77405 12.76226 12.74755
## [569] 12.72847 12.70559 12.67946 12.65066 12.61974 12.58727 12.55381 12.51992
## [577] 12.48616 12.45310 12.42130 12.39132 12.36373 12.33908 12.31794 12.29611
## [585] 12.26942 12.23845 12.20380 12.16606 12.12581 12.08366 12.04018 11.99598
## [593] 11.95163 11.90774 11.86489 11.82368 11.78469 11.74852 11.71575 11.68698
## [601] 11.66280 11.64380 11.62831 11.61420 11.60139 11.58979 11.57932 11.56989
## [609] 11.56142 11.55381 11.54699 11.54087 11.53536 11.53038 11.52584 11.52165
## [617] 11.51773 11.51400 11.51071 11.50820 11.50647 11.50551 11.50532 11.50590
## [625] 11.50724 11.50934 11.51221 11.51583 11.52021 11.52534 11.53122 11.53785
## [633] 11.54523 11.55335 11.56221 11.57181 11.58215 11.59323 11.60506 11.61764
## [641] 11.63098 11.64507 11.65993 11.67554 11.69191 11.70904 11.72694 11.74560
## [649] 11.76503 11.78523 11.80620 11.82794 11.85045 11.87371 11.89769 11.92238
## [657] 11.94779 11.97393 12.00079 12.02838 12.05670 12.08575 12.11553 12.14605
## [665] 12.17732 12.20932 12.24206 12.27556 12.30980 12.34479 12.38053 12.41703
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 672)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.60802 12.60430 12.60067 12.59712 12.59366 12.59028 12.58698 12.58376
## [9] 12.58062 12.57755 12.57456 12.57164 12.56878 12.56600 12.56328 12.56062
## [17] 12.55803 12.55549 12.55302 12.55060 12.54823 12.54592 12.54366 12.54145
## [25] 12.53928 12.53716 12.53508 12.53305 12.53105 12.52909 12.52717 12.52528
## [33] 12.52342 12.52160 12.51980 12.51803 12.51625 12.51446 12.51265 12.51082
## [41] 12.50900 12.50717 12.50535 12.50355 12.50177 12.50001 12.49829 12.49661
## [49] 12.49497 12.49338 12.49185 12.49039 12.48900 12.48768 12.48644 12.48530
## [57] 12.48425 12.48330 12.48246 12.48173 12.48112 12.48064 12.48029 12.48008
## [65] 12.48002 12.48011 12.48035 12.48076 12.48134 12.48209 12.48303 12.48409
## [73] 12.48523 12.48644 12.48773 12.48909 12.49052 12.49204 12.49364 12.49532
## [81] 12.49708 12.49893 12.50086 12.50288 12.50499 12.50720 12.50949 12.51188
## [89] 12.51436 12.51694 12.51961 12.52239 12.52527 12.52825 12.53133 12.53452
## [97] 12.53782 12.54122 12.54473 12.54836 12.55210 12.55595 12.55992 12.56400
## [105] 12.56820 12.57253 12.57671 12.58053 12.58401 12.58719 12.59010 12.59278
## [113] 12.59527 12.59759 12.59978 12.60188 12.60392 12.60593 12.60796 12.61003
## [121] 12.61218 12.61445 12.61686 12.61946 12.62228 12.62535 12.62870 12.63238
## [129] 12.63642 12.64085 12.64570 12.65102 12.65683 12.66403 12.67337 12.68465
## [137] 12.69766 12.71219 12.72804 12.74502 12.76291 12.78151 12.80062 12.82003
## [145] 12.83955 12.85897 12.87808 12.89668 12.91457 12.93154 12.94739 12.96192
## [153] 12.97493 12.98620 12.99861 13.01477 13.03413 13.05614 13.08023 13.10585
## [161] 13.13243 13.15943 13.18629 13.21244 13.23732 13.26039 13.28109 13.29885
## [169] 13.31311 13.32333 13.33153 13.34006 13.34885 13.35782 13.36690 13.37600
## [177] 13.38505 13.39398 13.40271 13.41117 13.41927 13.42694 13.43411 13.44069
## [185] 13.44662 13.45181 13.45619 13.45969 13.46222 13.46372 13.46410 13.46328
## [193] 13.46120 13.45778 13.45293 13.44659 13.43868 13.42912 13.41694 13.40146
## [201] 13.38301 13.36190 13.33846 13.31302 13.28591 13.25745 13.22797 13.19780
## [209] 13.16725 13.13666 13.10636 13.07666 13.04790 13.02040 12.99449 12.97049
## [217] 12.94874 12.92628 12.90022 12.87094 12.83882 12.80426 12.76765 12.72936
## [225] 12.68978 12.64930 12.60830 12.56718 12.52631 12.48609 12.44690 12.40912
## [233] 12.37315 12.33936 12.30815 12.27990 12.25499 12.23382 12.21474 12.19588
## [241] 12.17729 12.15903 12.14114 12.12367 12.10666 12.09017 12.07425 12.05894
## [249] 12.04429 12.03034 12.01716 12.00478 11.99326 11.98264 11.97401 11.96824
## [257] 11.96503 11.96412 11.96521 11.96803 11.97230 11.97773 11.98404 11.99096
## [265] 11.99819 12.00546 12.01249 12.01899 12.02469 12.02930 12.03254 12.03413
## [273] 12.03379 12.03454 12.03923 12.04727 12.05808 12.07109 12.08573 12.10142
## [281] 12.11757 12.13362 12.14898 12.16309 12.17536 12.18521 12.19208 12.19538
## [289] 12.19454 12.19099 12.18658 12.18137 12.17542 12.16877 12.16148 12.15361
## [297] 12.14522 12.13635 12.12707 12.11743 12.10747 12.09727 12.08687 12.07633
## [305] 12.06570 12.05504 12.04440 12.03384 12.02342 12.01318 12.00114 11.98557
## [313] 11.96688 11.94547 11.92177 11.89619 11.86914 11.84104 11.81231 11.78335
## [321] 11.75458 11.72642 11.69928 11.67357 11.64972 11.62812 11.60921 11.59339
## [329] 11.58108 11.56918 11.55462 11.53788 11.51942 11.49970 11.47919 11.45836
## [337] 11.43767 11.41759 11.39858 11.38111 11.36564 11.35264 11.34257 11.33591
## [345] 11.33312 11.33308 11.33437 11.33690 11.34063 11.34548 11.35141 11.35834
## [353] 11.36623 11.37500 11.38459 11.39496 11.40603 11.41774 11.43004 11.44287
## [361] 11.45615 11.46984 11.48387 11.49818 11.51445 11.53420 11.55713 11.58295
## [369] 11.61135 11.64203 11.67469 11.70903 11.74475 11.78155 11.81914 11.85720
## [377] 11.89544 11.93355 11.97125 12.00822 12.04418 12.07880 12.11181 12.14289
## [385] 12.17175 12.19809 12.22160 12.24475 12.27002 12.29713 12.32578 12.35569
## [393] 12.38657 12.41815 12.45013 12.48222 12.51415 12.54563 12.57636 12.60607
## [401] 12.63446 12.66126 12.68618 12.70893 12.72922 12.74677 12.76334 12.78075
## [409] 12.79878 12.81723 12.83589 12.85456 12.87301 12.89105 12.90847 12.92505
## [417] 12.94060 12.95489 12.96773 12.97891 12.98821 12.99543 13.00062 13.00405
## [425] 13.00583 13.00609 13.00494 13.00251 12.99892 12.99428 12.98871 12.98233
## [433] 12.97527 12.96764 12.95957 12.95116 12.94255 12.93385 12.92517 12.91665
## [441] 12.90840 12.89869 12.88590 12.87034 12.85230 12.83207 12.80996 12.78626
## [449] 12.76127 12.73528 12.70859 12.68150 12.65431 12.62731 12.60079 12.57507
## [457] 12.55042 12.52716 12.50557 12.48596 12.46861 12.45383 12.43892 12.42126
## [465] 12.40130 12.37948 12.35624 12.33203 12.30729 12.28246 12.25798 12.23430
## [473] 12.21186 12.19110 12.17246 12.15640 12.14334 12.13373 12.12565 12.11694
## [481] 12.10775 12.09823 12.08852 12.07876 12.06910 12.05968 12.05065 12.04214
## [489] 12.03431 12.02730 12.02124 12.01629 12.01259 12.01028 12.00950 12.01041
## [497] 12.01313 12.01811 12.02552 12.03516 12.04684 12.06033 12.07545 12.09198
## [505] 12.10973 12.12848 12.14803 12.16818 12.18873 12.20946 12.23018 12.25069
## [513] 12.27076 12.29021 12.30883 12.32641 12.34274 12.35764 12.37401 12.39463
## [521] 12.41904 12.44676 12.47734 12.51032 12.54523 12.58161 12.61900 12.65694
## [529] 12.69497 12.73262 12.76943 12.80494 12.83868 12.87021 12.89904 12.92473
## [537] 12.94681 12.96481 12.97828 12.98959 13.00133 13.01338 13.02562 13.03794
## [545] 13.05021 13.06232 13.07414 13.08556 13.09645 13.10670 13.11618 13.12478
## [553] 13.13238 13.13885 13.14408 13.14795 13.15034 13.15112 13.15019 13.14741
## [561] 13.14267 13.13585 13.12638 13.11393 13.09877 13.08118 13.06144 13.03981
## [569] 13.01656 12.99196 12.96630 12.93983 12.91284 12.88558 12.85835 12.83140
## [577] 12.80501 12.77945 12.75499 12.73190 12.71046 12.68675 12.65721 12.62264
## [585] 12.58386 12.54167 12.49688 12.45030 12.40273 12.35500 12.30789 12.26223
## [593] 12.21882 12.17848 12.14199 12.11019 12.08387 12.06021 12.03596 12.01124
## [601] 11.98620 11.96096 11.93568 11.91048 11.88549 11.86087 11.83674 11.81324
## [609] 11.79050 11.76867 11.74787 11.72826 11.70995 11.69310 11.67783 11.66428
## [617] 11.65259 11.64290 11.63442 11.62629 11.61857 11.61131 11.60455 11.59834
## [625] 11.59273 11.58777 11.58349 11.57996 11.57722 11.57532 11.57429 11.57420
## [633] 11.57509 11.57701 11.58000 11.58411 11.58940 11.59561 11.60248 11.61004
## [641] 11.61830 11.62730 11.63706 11.64759 11.65893 11.67109 11.68410 11.69798
## [649] 11.71275 11.72845 11.74508 11.76268 11.78126 11.80087 11.82150 11.84314
## [657] 11.86578 11.88940 11.91398 11.93951 11.96597 11.99335 12.02163 12.05080
## [665] 12.08084 12.11174 12.14347 12.17603 12.20939 12.24355 12.27848 12.31418
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 672)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 11.93728 11.93633 11.93540 11.93449 11.93359 11.93271 11.93184 11.93097
## [9] 11.93011 11.92925 11.92839 11.92752 11.92664 11.92575 11.92485 11.92393
## [17] 11.92298 11.92201 11.92102 11.92000 11.91894 11.91784 11.91671 11.91553
## [25] 11.91431 11.91303 11.91171 11.91033 11.90889 11.90739 11.90583 11.90420
## [33] 11.90249 11.90072 11.89886 11.89693 11.89491 11.89281 11.89062 11.88833
## [41] 11.88595 11.88348 11.88090 11.87815 11.87518 11.87202 11.86866 11.86514
## [49] 11.86145 11.85763 11.85369 11.84964 11.84549 11.84127 11.83699 11.83266
## [57] 11.82830 11.82393 11.81956 11.81521 11.81089 11.80662 11.80241 11.79829
## [65] 11.79426 11.79034 11.78655 11.78290 11.77941 11.77610 11.77298 11.77006
## [73] 11.76736 11.76491 11.76270 11.76076 11.75911 11.75776 11.75613 11.75365
## [81] 11.75040 11.74643 11.74180 11.73657 11.73080 11.72456 11.71789 11.71088
## [89] 11.70356 11.69601 11.68828 11.68044 11.67254 11.66465 11.65682 11.64912
## [97] 11.64160 11.63433 11.62736 11.62076 11.61459 11.60890 11.60376 11.59923
## [105] 11.59537 11.59224 11.58989 11.58839 11.58781 11.58819 11.58960 11.59210
## [113] 11.59575 11.60071 11.60703 11.61462 11.62337 11.63319 11.64399 11.65566
## [121] 11.66810 11.68123 11.69493 11.70911 11.72369 11.73854 11.75359 11.76873
## [129] 11.78386 11.79889 11.81372 11.82824 11.84237 11.85601 11.86905 11.88349
## [137] 11.90116 11.92175 11.94496 11.97046 11.99795 12.02712 12.05764 12.08922
## [145] 12.12154 12.15428 12.18713 12.21978 12.25192 12.28324 12.31342 12.34216
## [153] 12.36913 12.39403 12.41655 12.43636 12.45598 12.47791 12.50182 12.52741
## [161] 12.55437 12.58238 12.61115 12.64034 12.66966 12.69880 12.72743 12.75526
## [169] 12.78196 12.80723 12.83076 12.85224 12.87134 12.88778 12.90122 12.91314
## [177] 12.92514 12.93717 12.94915 12.96102 12.97270 12.98413 12.99523 13.00594
## [185] 13.01619 13.02591 13.03503 13.04348 13.05119 13.05809 13.06412 13.06920
## [193] 13.07327 13.07626 13.07809 13.07870 13.07802 13.07598 13.07252 13.06755
## [201] 13.06102 13.05285 13.04297 13.03132 13.01602 12.99568 12.97099 12.94262
## [209] 12.91126 12.87758 12.84228 12.80602 12.76950 12.73338 12.69835 12.66510
## [217] 12.63429 12.60662 12.58277 12.55887 12.53093 12.49937 12.46463 12.42714
## [225] 12.38734 12.34566 12.30252 12.25837 12.21365 12.16877 12.12418 12.08030
## [233] 12.03758 11.99645 11.95733 11.92067 11.88689 11.85643 11.82973 11.80721
## [241] 11.78695 11.76676 11.74669 11.72679 11.70712 11.68771 11.66862 11.64991
## [249] 11.63161 11.61378 11.59646 11.57972 11.56358 11.54812 11.53337 11.51939
## [257] 11.50622 11.49391 11.48251 11.47355 11.46820 11.46601 11.46650 11.46923
## [265] 11.47373 11.47953 11.48619 11.49324 11.50021 11.50666 11.51211 11.51612
## [273] 11.51821 11.51793 11.51481 11.51187 11.51214 11.51523 11.52077 11.52835
## [281] 11.53758 11.54808 11.55946 11.57132 11.58327 11.59492 11.60589 11.61578
## [289] 11.62420 11.63076 11.63507 11.63674 11.63538 11.63060 11.62243 11.61135
## [297] 11.59764 11.58160 11.56352 11.54367 11.52236 11.49986 11.47646 11.45246
## [305] 11.42814 11.40378 11.37969 11.35613 11.33341 11.31180 11.29160 11.27310
## [313] 11.25658 11.24232 11.23063 11.21824 11.20211 11.18281 11.16093 11.13707
## [321] 11.11179 11.08569 11.05935 11.03336 11.00831 10.98477 10.96333 10.94458
## [329] 10.92911 10.91749 10.91031 10.90608 10.90290 10.90072 10.89951 10.89925
## [337] 10.89990 10.90142 10.90378 10.90696 10.91091 10.91561 10.92102 10.92711
## [345] 10.93385 10.94120 10.94913 10.95760 10.96659 10.97606 10.98729 11.00137
## [353] 11.01797 11.03676 11.05743 11.07965 11.10310 11.12744 11.15237 11.17755
## [361] 11.20267 11.22739 11.25140 11.27436 11.29597 11.31589 11.33580 11.35750
## [369] 11.38086 11.40571 11.43192 11.45935 11.48783 11.51724 11.54742 11.57823
## [377] 11.60952 11.64115 11.67297 11.70483 11.73659 11.76811 11.79924 11.82982
## [385] 11.85973 11.88880 11.91690 11.94388 11.96960 11.99390 12.01664 12.03768
## [393] 12.05874 12.08142 12.10545 12.13053 12.15638 12.18271 12.20924 12.23568
## [401] 12.26173 12.28712 12.31155 12.33474 12.35639 12.37624 12.39397 12.40932
## [409] 12.42335 12.43731 12.45113 12.46473 12.47806 12.49104 12.50362 12.51572
## [417] 12.52728 12.53822 12.54850 12.55803 12.56675 12.57460 12.58151 12.58741
## [425] 12.59224 12.59592 12.59840 12.59882 12.59658 12.59199 12.58537 12.57702
## [433] 12.56727 12.55642 12.54479 12.53270 12.52045 12.50836 12.49675 12.48592
## [441] 12.47619 12.46788 12.46129 12.45462 12.44598 12.43553 12.42349 12.41002
## [449] 12.39533 12.37959 12.36301 12.34575 12.32802 12.31000 12.29188 12.27384
## [457] 12.25608 12.23877 12.22212 12.20631 12.19152 12.17794 12.16576 12.15517
## [465] 12.14503 12.13413 12.12258 12.11048 12.09796 12.08511 12.07204 12.05887
## [473] 12.04569 12.03262 12.01976 12.00723 11.99513 11.98356 11.97264 11.96248
## [481] 11.95318 11.94485 11.93759 11.93038 11.92223 11.91335 11.90392 11.89415
## [489] 11.88424 11.87438 11.86477 11.85561 11.84709 11.83942 11.83279 11.82741
## [497] 11.82346 11.82115 11.82067 11.82158 11.82330 11.82578 11.82898 11.83288
## [505] 11.83742 11.84258 11.84832 11.85460 11.86137 11.86862 11.87629 11.88435
## [513] 11.89276 11.90149 11.91050 11.91975 11.92920 11.93882 11.94857 11.95841
## [521] 11.96978 11.98399 12.00078 12.01991 12.04115 12.06425 12.08897 12.11506
## [529] 12.14227 12.17038 12.19913 12.22828 12.25758 12.28680 12.31569 12.34401
## [537] 12.37151 12.39796 12.42310 12.44670 12.46851 12.48828 12.50579 12.52077
## [545] 12.53300 12.54222 12.55030 12.55917 12.56869 12.57871 12.58909 12.59970
## [553] 12.61039 12.62102 12.63144 12.64152 12.65111 12.66008 12.66827 12.67556
## [561] 12.68179 12.68683 12.69053 12.69275 12.69335 12.69220 12.68914 12.68324
## [569] 12.67392 12.66160 12.64669 12.62961 12.61077 12.59058 12.56946 12.54781
## [577] 12.52606 12.50461 12.48388 12.46428 12.44623 12.43013 12.41641 12.40176
## [585] 12.38293 12.36041 12.33465 12.30614 12.27536 12.24276 12.20884 12.17406
## [593] 12.13890 12.10383 12.06932 12.03585 12.00390 11.97394 11.94644 11.92188
## [601] 11.90072 11.88346 11.86802 11.85213 11.83594 11.81960 11.80327 11.78710
## [609] 11.77124 11.75585 11.74106 11.72704 11.71394 11.70191 11.69110 11.68167
## [617] 11.67376 11.66752 11.66237 11.65763 11.65332 11.64948 11.64614 11.64334
## [625] 11.64109 11.63945 11.63843 11.63806 11.63839 11.63944 11.64124 11.64382
## [633] 11.64722 11.65147 11.65660 11.66263 11.66961 11.67739 11.68581 11.69488
## [641] 11.70460 11.71499 11.72605 11.73779 11.75023 11.76336 11.77719 11.79174
## [649] 11.80701 11.82301 11.83976 11.85724 11.87548 11.89450 11.91428 11.93484
## [657] 11.95616 11.97825 12.00108 12.02465 12.04897 12.07402 12.09980 12.12630
## [665] 12.15352 12.18145 12.21008 12.23941 12.26943 12.30013 12.33151 12.36357
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")